﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using RZD_maps.Modules.Transport.ViewModels;

namespace RZD_maps.Modules.Transport.Views
{
    /// <summary>
    /// Логика взаимодействия для View.xaml
    /// </summary>
    public partial class View : UserControl
    {
        private ViewModel view_model;

        public View()
        {
            InitializeComponent();
        }

        public View(ViewModel view_model)
            : this()
        {
            this.view_model = view_model;
            view_model.View = this;
        }

        private void CategoryTree_SelectedItemChanged(object sender, Hardcodet.Wpf.GenericTreeView.RoutedTreeItemEventArgs<Models.TransportCategory> e)
        {
            int Id;
            double Lat = 0.0;
            double Lng = 0.0;
            try
            {
                Id = e.NewItem.Id;
                view_model.GetLatLongById(Id, out Lat, out Lng);
                if (Lng != 0.0 && Lat != 0.0)
                {
                    view_model.TransferMapPosition(Lng, Lat, 10);
                    view_model.TransferGraphicInfo(string.Format("{2} - {0},{1}",Lng, Lat,e.NewItem.CategoryName));
                }
            }
            catch
            {
            }

        }
    }
}
